<?php 
include("includes/code.php");

if (isset($_GET['id'])) { $id_news = $_GET['id']; }

$result = mysql_query("SELECT title,text FROM pages WHERE page='news'",$db);
if (!$result)
{ myerror("XATOLIK ! Bazadagi Pages jadvalidan malumotlar olinmadi"); }

$myrow = mysql_fetch_array($result);
$title = stripslashes($myrow["title"]);
$text = stripslashes($myrow["text"]);

///// headerni olamiz
include("includes/header.php"); 
?>

<!-- content and sidebar -->
<div id="main">
<table class="main_table" cellspacing="0" cellpadding="0">
  <tr valign="top">
    <td class="left_col">
<!-- ------------- left start ------------- -->
<?php include("includes/left.php"); ?>
    
<!-- ----------------- left finish ---------------- -->
    </td>
    <td>
<div class="content">
<!-- content start -->

<h4 class="sarlavha"><?php echo $title ?></h4>
<?php 
if(!isset($id_news))
{

echo "<p> $text </p>";

// paging uchun
$num = 10; /* bitta sahifadagi malumotlar soni */
@$page = $_GET['page']; 
$result00 = mysql_query("SELECT COUNT(*) FROM news"); /* bazada nechta elon borligini aniqla */
$temp = mysql_fetch_array($result00);
$posts = $temp[0];
$total = (($posts - 1) / $num) + 1; // nechta sahifa kerakligi aniqlanishi
$total =  intval($total); // butun songa aylantiramiz 
$page = intval($page); // tegishli sahifa uchun aniqlash
if(empty($page) or $page < 0) { $page = 1; }
else  if($page > $total) { $page = $total; }
$start = $page * $num - $num;
// paging finish
$result_news = mysql_query("SELECT id_news, title_news, izoh_news, img_news FROM news ORDER by id_news DESC LIMIT $start, $num", $db);
	if (!$result_news)
	{ myerror("XATOLIK ! Bazadagi news jadvalidan malumotlar olinmadi");}
	
	if(mysql_num_rows($result_news) > 0)
	{
		while(list($id_news, $title_news, $izoh_news, $img_news) = mysql_fetch_array($result_news))
		{
		$izoh_news = stripslashes($izoh_news);
		$title_news = stripslashes($title_news);
		if($img_news == "") { $noimg='style="display:none"'; } else {$noimg='';}
		echo "
		<div class='news'> 
			<img src='$img_news' class='news_img' alt='' title='' $noimg /> 
			<p><b><a href='news.php?id=$id_news'> $title_news </a></b></p> $izoh_news 
			<p><a href='news.php?id=$id_news'>".READ."</a></p>
		</div>";
		}
// eng yaqin sahifalarni aniqlasymiz
if($page - 5 > 0) $page5left = ' <a href=news.php?page='. ($page - 5) .'>'. ($page - 5) .'</a>  ';
if($page - 4 > 0) $page4left = ' <a href=news.php?page='. ($page - 4) .'>'. ($page - 4) .'</a>  ';
if($page - 3 > 0) $page3left = ' <a href=news.php?page='. ($page - 3) .'>'. ($page - 3) .'</a>  ';
if($page - 2 > 0) $page2left = ' <a href=news.php?page='. ($page - 2) .'>'. ($page - 2) .'</a>  ';
if($page - 1 > 0) $page1left = '<a href=news.php?page='. ($page - 1) .'>'. ($page - 1) .'</a>  ';

if($page + 5 <= $total) $page5right = '  <a href=news.php?page='. ($page + 5) .'>'. ($page + 5) .'</a>';
if($page + 4 <= $total) $page4right = '  <a href=news.php?page='. ($page + 4) .'>'. ($page + 4) .'</a>';
if($page + 3 <= $total) $page3right = '  <a href=news.php?page='. ($page + 3) .'>'. ($page + 3) .'</a>';
if($page + 2 <= $total) $page2right = '  <a href=news.php?page='. ($page + 2) .'>'. ($page + 2) .'</a>';
if($page + 1 <= $total) $page1right = '  <a href=news.php?page='. ($page + 1) .'>'. ($page + 1) .'</a>';

	// agar sahifa 1 tadan ortiq bulsa raqam chiqarish
	if ($total > 1)
	{
	Error_Reporting(E_ALL & ~E_NOTICE);
	echo "<div class=\"pages\" align=\"center\"> Page: &nbsp;";
	echo $pervpage.$page5left.$page4left.$page3left.$page2left.$page1left.'<span class="this">' .$page. '</span>'.$page1right.$page2right.$page3right.$page4right.$page5right.$nextpage;
	echo "</div>";
	}
	/* sahifa raqami finish */	
	}
	else {echo "<p>No news in this page</p>"; }

}
else
{
//////// sahifani batafsil chiqarish
	$result_news = mysql_query("SELECT title_news, text_news, img_news, time_news FROM news WHERE id_news='$id_news'");
	if(mysql_num_rows($result_news) > 0)
	{
	$row_news = mysql_fetch_array($result_news);
	  $title_news = stripslashes($row_news["title_news"]);
	  $text_news = stripslashes($row_news["text_news"]);
	  $img_news = $row_news["img_news"];
	  $time_sql = $row_news["time_news"];
	  $date=ConvertDate($time_sql);	
	  
	  if($img_news == "") { $noimg='style="display:none"'; } else {$noimg='';}		
?>
<!-- yangilik haqida batafsil -->
	<div class='news'>
        <img src='<?= $img_news ?>' class='news_img' alt='' title='' <?= $noimg ?> /> 
        <p>
        <b><?= $title_news ?> </b> <span style="float:right; font-size:12px; color:#666666">Yozildi: <?= $date ?></span>
        <?= $text_news  ?>
        </p> 
    </div>
<!-- yangilik haqida batafsil finish --> 
	<p><a href="javascript: history.back()"> &lt; Orqaga qaytish</a> </p>
<?php
	}
	else
	{ echo "<p>Bazada bunday malumot mavjud emas</p>"; }
}
?>

<!-- content finish -->
</div>
    </td>
    <td class="right_col">
<!-- -------- right start ----------- -->
<?php include("includes/right.php"); ?>
<!-- --------- right finish ------- -->
    </td>
  </tr>
</table>

</div>
<!-- content and sidebar finish -->

</div>
<!-- main container finish -->
<?php include("includes/footer.php"); ?>